package org.paradigmshift.timelapse

import org.paradigmshift.timelapse.ui.TimeLapseUI
import java.util.prefs.Preferences
import java.net.URI
import org.paradigmshift.timelapse.daos.IssueDao
import org.paradigmshift.timelapse.daos.WorklogDao
import org.paradigmshift.timelapse.rest.ServerUriActor
import org.paradigmshift.timelapse.rest.JsonRestConnection
import org.paradigmshift.timelapse.domain.Worklog
import java.util.Date
import org.paradigmshift.timelapse.rest.ServerUriActor
import org.paradigmshift.timelapse.ui.LoginDialog
import org.paradigmshift.timelapse.ui.OSValidator
import java.util.Properties

/**
 * @author ${user.name}
 */
object TimeLapseApp {
  
  val appName = "Time Lapse"
  val version = try {
    val props = new Properties()
    props.load( getClass().getClassLoader().getResourceAsStream( "application.properties" ) )
    props.getProperty( "timelapse.version", "A bad one!" )
  }
  catch {
    case e:Exception => "A bad one!"
  }
    
  def main( args:Array[String] ) {
    
    // Set the app name
    if ( OSValidator.isMac ) System.setProperty( "com.apple.mrj.application.apple.menu.about.name", appName )
    else if ( OSValidator.isLinux ) {
      val awtAppClassNameField = TimeLapseUI.toolkit.getClass.getDeclaredField( "awtAppClassName" )
      awtAppClassNameField.setAccessible( true )
      awtAppClassNameField.set( TimeLapseUI.toolkit, appName )
    }
    
    // Load connection settings from preferences
    JsonRestConnection.setConnectionInfo( TimeLapsePreferences.getScheme, TimeLapsePreferences.getHost, TimeLapsePreferences.getPort )
    
    // Start the UI
    new TimeLapseUI().startup( new Array( 0 ) )
  }
}
